//
//  picCollectionView.swift
//  WeiBo
//
//  Created by LTX on 2016/12/5.
//  Copyright © 2016年 LTX. All rights reserved.
//

import UIKit

class picCollectionView: UICollectionView {
    
    
    //图像URL数组
    var picURLArray : [NSURL] = [NSURL](){
        didSet{
            //一旦被赋值就刷新
            reloadData()
        }
    }
    
        

    //系统回调函数
    override func awakeFromNib() {
        super.awakeFromNib()
        
        dataSource = self
        
        register(UINib(nibName: "picCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "picCell")
        
    }

}


// MARK:- 数据源代理方法
extension picCollectionView :UICollectionViewDataSource{
    
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        
        return picURLArray.count
    }
    
    
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = collectionView .dequeueReusableCell(withReuseIdentifier: "picCell", for: indexPath) as! picCollectionViewCell
        
        cell.picURL = picURLArray[indexPath.item]
        
        
        return cell
        
    }
    
}
